from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
    def minimumRecolors(self, blocks: str, k: int) -> int:
        # 看题 就是  固定窗口中k最少的白色块
        ans = -1  # ans 最终的答案
        vocal = 0  # 当前窗口有几个白色块
        for right, wb in enumerate(blocks):
            if wb == 'W':
                vocal += 1

            left = right - k + 1
            if left >= 0:
                ans = vocal if ans == -1 else min(ans, vocal)
                if ans == 0:
                    return 0
                if blocks[left] == 'W':
                    vocal -= 1
        return ans
# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    print(solution.minimumRecolors("WBBWWBBWBW",7))
    # your test code here